package com.example.lvsuo.service.impl;

import com.example.lvsuo.entity.LogType;
import com.example.lvsuo.service.ICwInoutTypeService;
import com.example.lvsuo.entity.CwInoutType;
import com.example.lvsuo.mapper.CwInoutTypeMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 心心念念
 * @since 2021-03-30
 */
@Service
public class CwInoutTypeServiceImpl extends ServiceImpl<CwInoutTypeMapper, CwInoutType> implements ICwInoutTypeService {

    @Override
    public List<CwInoutType>  Getlists() {
        return  thiss( this.baseMapper.Getlists(),0);
    }

    @Override
    public List<CwInoutType> Getlistsmo() {
        return  thiss( this.baseMapper.Getlistsmo(),0);
    }

    //递归
    public List<CwInoutType> thiss(List<CwInoutType>  list , int id){

        List<CwInoutType> collect = list.stream().filter(a -> a.getCwPid()==id).map(a -> {
            List<CwInoutType> menus = thiss(list,Integer.valueOf(a.getId().toString()));
            a.setChildren(menus);
            return a;
        }).collect(Collectors.toList());
        return  collect;
    }
}
